import { queryPlainText, addPlainText,removePlainText,updatePlainText,removeAllPlainText,queryListByTypeCode,preview} from '@/services/bnsConfig/plainText';

export default {
  namespace: 'plainText',

  state: {
    // 列表数据
    data: {
      dataList: [],
      pageNum: 0,
      pageSize: 0,
      totalCount: 0,
    },
    fileTypeData: [],
    fontData:[],
    queryForm:{},
  },

  effects: {
    *queryList({ payload }, { call, put }) {
      const response = yield call(queryPlainText, payload);
      yield put({
        type: 'save',
        payload: response,
      });
    },
    *add({ payload, callback }, { call, put }) {
      const response = yield call(addPlainText, payload);
      yield put({
        type: 'saveadd',
        payload: response,
      });
      if (callback) callback(response);
    },
    *remove({ payload, callback }, { call, put }) {
      const response = yield call(removePlainText, payload);
      yield put({
        type: 'saveremove',
        payload: response,
      });
      if (callback) callback(response);
    },
    *update({ payload, callback }, { call, put }) {
      const response = yield call(updatePlainText, payload);
      yield put({
        type: 'saveupdate',
        payload: response,
      });
      if (callback) callback(response);
    },

    *byTypeCode({ payload, callback }, { call, put }) {
        const response = yield call(queryListByTypeCode, payload);
        yield put({
          type: 'fileType',
          payload: response,
        });
        if (callback) callback(response);
      },
      *preview({ payload, callback }, { call, put }) {
        const response = yield call(preview, payload);
        yield put({
          type: 'review',
          payload: response,
        });
        if (callback) callback(response);
      },      
  },

  reducers: {
    save(state, action) {
      return {
        ...state,
        data: action.payload.data,
      };
    },

    // fileType(state, action) {
    //   return {
    //     ...state,
    //     fileTypeData: action.payload.data.dataList,
    //   };
    // },

    // font(state, action) {
    //   return {
    //     ...state,
    //     fontData: action.payload.data.dataList,
    //   };
    // },

    // fontSize(state, action) {
    //   return {
    //     ...state,
    //     fontSizeData: action.payload.data.dataList,
    //   };
    // },

  },
};
